﻿//﻿if (typeof (Founder) == "undefined") { Founder = { __namespace: true }; }
LoadKnowlegdeList = function () {
    var datas = new Object();
    datas.Parms = new Array();
    datas.Parms[0] = $("#SearchTxt").val();
    datas.RequestName = "GetknowlegdeList";
    datas = window.JSON.stringify(datas);
    $.ajax({
        async: false,
        type: "Post",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        url: '/springservice.ashx?op=CustomRequest&custom=1',
        data: datas,
        success: function (data) {
            if (data.returnValue == true) {
                var responseData = data.MainData;
                var showData = "";
                if (data.MainData.length == 0) {
                    showData += "<div  style=' width:100%; text-align:center;'>没有找到相关文件<div>";
                }
                else {
                    $.each(data.MainData, function (i, n) {
                        showData += "<li><a href='" + n.Url + "' target='_blank' >" + n.Title + "</a></li>";
                    });
                }
                $('#KnowLedgeList').html(showData);
            }
            else {
                alert('错误：' + data.message);
            }
        },
        error: function (data) {
            alert("errorText:" + data.message);
        }
    });
}
LoadNoticeList = function () {
    var datas = new Object();
    datas.Parms = new Array();

    datas.RequestName = "GetNotices";

    datas = window.JSON.stringify(datas);
    $.ajax({
        async: false,
        type: "Post",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        url: '/springservice.ashx?op=CustomRequest&custom=1',
        data: datas,
        success: function (data) {
            if (data.returnValue == true) {
                var responseData = data.MainData;
                var showData = "";
                var i = 0;
                $.each(data.MainData, function (i, n) {
                    if (i != 0) {
                        showData += "<li><a target='_blank' href='NoticeContent.aspx?id=" + n.SPId + "'>" + n.Title + "(" + n.CreateTime + ")" + "</a></li>";
                    }
                    else {
                        $("#FirstNotice").html(n.Body);
                        $("#NoticeTitle").html(n.Title);
                    }
                    i++;
                });
                //alert(showData);
                $('#NoticeList').html(showData);

            }
            else {
                alert('错误：' + data.message);
            }
        },
        error: function (data) {
            alert("errorText:" + data.message);
        }
    });
}



LoadUserTask = function (TableType) {
    var datas = new Object();
    datas.Parms = new Array();
    datas.Parms[0] = TableType;
    datas.RequestName = "GetMySelfData";

    datas = window.JSON.stringify(datas);
    $.ajax({
        async: false,
        type: "Post",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        url: '/springservice.ashx?op=GetListRequest&custom=1',
        data: datas,
        success: function (data) {
            if (data.returnValue == true) {
                var responseData = data.MainData;

                $.each(data.MainData, function (i, n) {
                    n.ProcName = "<a href='" + GetOALink(n.ProcID, n.TaskID, n.StatusInt) + "' target='_blank' >" + n.ProcName + "</a>";
                });
                //                        var pageData = new Object;
                //                        pageData.total = data.MainData.length;
                //                        pageData.rows = data.MainData;
                //                        alert(window.JSON.stringify(pageData));
                //                if(data.MainData.length==0)
                //                {
                //                
                //               var vc=$('#MyWorks').datagrid('getPanel').children('div.datagrid-view');
                //              // alert(vc.html());
                //               //vc.html(vc.html()+"<br/>没有相关记录")
                //               var d=$('<div class="datagrid-empty"></div>').html('没有相关记录').appendTo(vc);
                //               d.css({
                //                position:'absolute',
                //                left:0,
                //                top:50,
                //                width:'100%',
                //                height:40,
                //                textAlign:'center'
                //            });
                //                }

                //              if(data.MainData.length==0)
                //              {
                //                    $('#MyWorks').html('没有相关记录');
                //              }
                var controlName = "";
                if (TableType == 0) {
                    controlName = "#MyWorks_Unstart";
                }
                else if (TableType == 1) {
                    controlName = "#MyWorks_UnFinish";
                }
                if (TableType == 2) {
                    controlName = "#MyWorks_Finish";
                }
                if (controlName != "") {
                    $(controlName).datagrid({ loadFilter: pagerFilter }).datagrid('loadData', data.MainData);
                    $(controlName).datagrid('getPager').pagination({
                        onRefresh: function (pageNumber, pageSize) {
                            LoadUserTask(TableType);
                        }
                    });
                }
            }
            else {
                alert('错误：' + data.message);
            }
        },
        error: function (data) {
            alert("errorText:" + data.message);
        }
    });
}
//    var myview = $.extend({},$.fn.datagrid.defaults.view,{
//    onAfterRender:function(target){
//        $.fn.datagrid.defaults.view.onAfterRender.call(this,target);
//        var opts = $(target).datagrid('options');
//        var vc = $(target).datagrid('getPanel').children('div.datagrid-view');
//        vc.children('div.datagrid-empty').remove();
//        if (!$(target).datagrid('getRows').length){
//            var d = $('<div class="datagrid-empty"></div>').html(opts.emptyMsg || 'no records').appendTo(vc);
//            d.css({
//                position:'absolute',
//                left:0,
//                top:50,
//                width:'100%',
//                textAlign:'center'
//            });
//        }
//        }
//    });
LoadUserProcessTask = function (TableType) {
    var datas = new Object();
    datas.Parms = new Array();
    datas.Parms[0] = TableType;
    datas.RequestName = "GetNeedProcessData";

    datas = window.JSON.stringify(datas);
    $.ajax({
        async: false,
        type: "Post",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        url: '/springservice.ashx?op=GetListRequest&custom=1',
        data: datas,
        success: function (data) {
            if (data.returnValue == true) {
                var responseData = data.MainData;

                $.each(data.MainData, function (i, n) {
                    n.ProcName = "<a href='" + GetOALink(n.ProcID, n.TaskID, n.StatusInt) + "' target='_blank'>" + n.ProcName + "</a>";
                });
                var controlName = "";
                if (TableType == 0) {
                    controlName = "#NeedProcessWorks";
                }
                else if (TableType == 1) {
                    controlName = "#NeedProcessFinishWorks";
                }
                if (controlName != "") {
                    $(controlName).datagrid({ loadFilter: pagerFilter }).datagrid('loadData', data.MainData);
                    $(controlName).datagrid('getPager').pagination({
                        onRefresh: function (pageNumber, pageSize) {
                            LoadUserProcessTask(TableType);
                        }
                    });
                }
            }
            else {
                alert('错误：' + data.message);
            }
        },
        error: function (data) {
            alert("errorText:" + data.message);
        }
    });
}

InitGroupTasks = function () {
    var datas = new Object();
    datas.Parms = new Array();
    datas.RequestName = "ITsupport_GetGroupNeedProcessData";

    datas = window.JSON.stringify(datas);
    $.ajax({
        async: false,
        type: "Post",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        url: '/springservice.ashx?op=GetListRequest',
        data: datas,
        success: function (data) {
            if (data.returnValue == true) {
                var responseData = data.MainData;

                $.each(data.MainData, function (i, n) {
                    n.ProcName = "<a href='" + GetOALink(n.ProcID, n.TaskID, n.StatusInt) + "' target='_blank'>" + n.ProcName + "</a>";
                });
                $('#GroupProcessWorks').datagrid({ loadFilter: pagerFilter }).datagrid('loadData', data.MainData);

                $('#GroupProcessWorks').datagrid('getPager').pagination({
                    onRefresh: function (pageNumber, pageSize) {
                        InitGroupTasks();
                    }
                });
            }
            else {
                alert('错误：' + data.message);
            }
        },
        error: function (data) {
            alert("errorText:" + data.message);
        }
    });
}

InitGroupFinishTasks = function () {
    var datas = new Object();
    datas.Parms = new Array();
    datas.RequestName = "ITsupport_GetGroupFinishedData";

    datas = window.JSON.stringify(datas);
    $.ajax({
        async: false,
        type: "Post",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        url: '/springservice.ashx?op=GetListRequest',
        data: datas,
        success: function (data) {
            if (data.returnValue == true) {
                var responseData = data.MainData;

                $.each(data.MainData, function (i, n) {
                    n.ProcName = "<a href='" + GetOALink(n.ProcID, n.TaskID, n.StatusInt) + "' target='_blank'>" + n.ProcName + "</a>";
                });
                $('#GroupFinishProcessWorks').datagrid({ loadFilter: pagerFilter }).datagrid('loadData', data.MainData);

                $('#GroupFinishProcessWorks').datagrid('getPager').pagination({
                    onRefresh: function (pageNumber, pageSize) {
                        InitGroupFinishTasks();
                    }
                });
            }
            else {
                alert('错误：' + data.message);
            }
        },
        error: function (data) {
            alert("errorText:" + data.message);
        }
    });
}
function pagerFilter(data) {
    if (typeof data.length == 'number' && typeof data.splice == 'function') {	// is array
        data = {
            total: data.length,
            rows: data
        }
    }
    var dg = $(this);
    var opts = dg.datagrid('options');
    var pager = dg.datagrid('getPager');
    pager.pagination({
        onSelectPage: function (pageNum, pageSize) {
            opts.pageNumber = pageNum;
            opts.pageSize = pageSize;
            pager.pagination('refresh', {
                pageNumber: pageNum,
                pageSize: pageSize
            });
            dg.datagrid('loadData', data);
        }
    });
    if (!data.originalRows) {
        data.originalRows = (data.rows);
    }
    var start = (opts.pageNumber - 1) * parseInt(opts.pageSize);
    var end = start + parseInt(opts.pageSize);
    data.rows = (data.originalRows.slice(start, end));
    return data;
}


var ShowContent = function (ID) {
    // alert("#Notice_body_"+ID);
    $("#Notice_body_" + ID).toggle();
}


var SearchStatisticResult = function (ddlperson, ddlsysName) {
    var datas = new Object();
    datas.Parms = new Array();
    datas.Parms[0] = $("#TBStart").datetimebox('getValue');
    //alert($("#TBStart"));
    datas.Parms[1] = $("#TBEnd").datetimebox('getValue');

    if (datas.Parms[0] != "" && datas.Parms[1] != "" && datas.Parms[0] > datas.Parms[1]) {
        alert("开始时间不能大于结束时间");
        return;
    }

    datas.Parms[2] = $(ddlperson).val();
    datas.Parms[3] = $(ddlsysName).val();
    datas.Parms[4] = $('#DDLProbList').val();
    datas.RequestName = "StatisticsSearch";

    datas = window.JSON.stringify(datas);
    $.ajax({
        async: false,
        type: "Post",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        url: '/springservice.ashx?op=GetListRequest&custom=1',
        data: datas,
        success: function (data) {
            if (data.returnValue == true) {
                var responseData = data.MainData;

                $("#TBSearchResult").html("共找到 "+data.MainData.length+" 条记录" )
                $.each(data.MainData, function (i, n) {
                    // n.ProcName = "<a href='" + GetOALink(n.ProcID, n.TaskID, n.StatusInt) + "' target='_blank'>" + n.ProcName + "</a>";
                });
                var controlName = "#GroupFinishProcessWorks";
                if (controlName != "") {
                    $(controlName).datagrid({ loadFilter: pagerFilter }).datagrid('loadData', data.MainData);
                    $(controlName).datagrid('getPager').pagination({
                        onRefresh: function (pageNumber, pageSize) {
                            SearchStatisticResult(ddlperson, ddlsysName);
                        }
                    });
                }
            }
            else {
                alert('错误：' + data.message);
            }
        },
        error: function (data) {
            alert("errorText:" + data.message);
        }
    });
}